package com.zodiac.app.datathinking.endpoint;

import com.github.lzm320a99981e.quickly.starter.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Controller
@RequestMapping("${" + Constants.ENV_PREFIX + "api.router.public-prefix:/public}")
public class PdfjsEndpoint {

    @GetMapping("index")
    public String index() {
        return "index";
    }

    @GetMapping(value = "/viewPdf")
    public void viewPdf(HttpServletResponse response) {
        try {
//            Path source = Paths.get("/Users/zhangguangyong/IdeaProjects/myprojects/zodiac-parent/zodiac-app-parent/zodiac-app-datathinking/B0602/pdf/中弘股份：2015年半年度报告.pdf");
//            Path source = Paths.get("/Users/zhangguangyong/IdeaProjects/myprojects/zodiac-parent/zodiac-app-parent/zodiac-app-datathinking/src/main/resources/static/pdfjs/web/compressed.tracemonkey-pldi-09.pdf");
            Path source = Paths.get("/Users/zhangguangyong/IdeaProjects/myprojects/zodiac-parent/zodiac-app-parent/zodiac-app-datathinking/B0602/pdf/中弘股份：2018年第一季度报告全文.pdf");
            response.getOutputStream().write(Files.readAllBytes(source));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
